﻿@using PNProject.EF;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout1.cshtml";
    int active = Convert.ToInt16(ViewData["page-active"]);
    int total = (int)(ViewData["page-total"]);
    int pc = (int)(ViewData["page-pc"]);
    List<int> listPage = (List<int>)(ViewData["page-list"]);
    List<News> news = (List<News>)(ViewData["news"]);
    int last = 1;
    if (listPage.Count > 1)
    {
        last = listPage.ElementAt(listPage.Count - 1);
    }
    bool lang = (bool)(ViewData["lang"]);
    string langText = lang ? "" : "en-US/";
    string query = ViewData["query"].ToString();
}

<div class="search-bv">
    <form name="input" action="/@string.Concat(langText,"articles/search")" method="get">
        <input type="text" name="query" placeholder="Từ khóa bài viết" style="width:640px; height:16px; float:left; padding:5px 10px; border:1px solid #ddd; background:white; color:#333;" />
        <input type="submit" value="Search" style="width:68px; height:28px; float:right;" />
    </form>
</div>
<div class="hienthikq">
                    	<p>Kết quả từ khóa: "@query" tìm thấy @total kết quả</p>
</div>
<div class="baiviet" style="margin-top:10px;">
@foreach (var item in news)
{

    DateTime time = item.CreateDate.HasValue?item.CreateDate.Value:DateTime.Now;
    <div class="boxbaiviet">
        <ul>
            <li class="CI">
                <a href="/@string.Concat(langText,"articles/detail/",item.TLink)">@item.Title</a>
                <p>@PNProject.PNLibraries.PNTimeFormat(time,false,lang)</p>
            </li>
            <li class="CII">
                @*<span>Trả lời: 5</span>*@
                <p>Xem: @item.ViewCount.ToString()</p>
            </li>
        </ul>
    </div>
}



</div>
<div class="pageT">
        <ul>
            <li><a href="/@string.Concat(langText,"articles/index?p=1")">Trang đầu</a></li>
            @foreach (var item in listPage)
            {
                if (item == active)
                {
                     <li class="active"><a href="/@string.Concat(langText, "articles/index?p=", item.ToString())">@item.ToString()</a></li>
                }
                else
                {
                    <li><a href="/@string.Concat(langText, "articles/index?p=", item.ToString())">@item.ToString()</a></li>
                }
            }
            @if (last < pc)
            {
            <li><a href="/@string.Concat(langText, "articles/index?p=", (last + 1).ToString())">...</a></li>
            <li><a href="#"><img src="/images/icon-14.png" alt="" /></a></li>
            }
            <li><a href="/@string.Concat(langText, "articles/index?p=", pc.ToString())">Trang cuối</a></li>
        </ul>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".titlesub p").empty();
            $(".titlesub p").append("Bài viết");
        });
</script>